package com.lims.util;

import java.util.ArrayList;
import java.util.List;

public class Pagination {
	//�ܼ�¼��
	private int totalLines;
	//ÿҳ��¼����
	private int pageSize;
	//��ǰҳ
	private int currentPage;
	//�Ƿ�����һҳ
	private boolean hasNextPage;
	//�Ƿ�����һҳ
	private boolean hasPrePage;
	
	public void setCurrentPage(int currentPage) {
		if(currentPage<=1)
			this.currentPage=1;
		else if(currentPage>=getTotalPages())
			this.currentPage=getTotalPages();
		else
			this.currentPage=currentPage;
	}


	public int getTotalLines() {
		return totalLines;
	}




	public Pagination(int totallines, int pagesize) {
		super();
		this.totalLines = totallines;
		this.pageSize = pagesize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	//�õ���ҳ��
	public int getTotalPages(){
		return (int)Math.ceil(totalLines/(double)pageSize);
	}
	
	//�õ�ÿҳ��һ����¼
	public int getFirstNote(){
		return (currentPage-1)*pageSize;
	}
	
	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}


	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}


	/**
	 * �Ƿ�����һҳ
	 * 
	 * @return
	 */
	public boolean getHasNextPage() {
		if (currentPage >= getTotalPages()) {
			return false;
		}
		return true;
	}

	/**
	 * �Ƿ�����һҳ
	 * 
	 * @return
	 */
	public boolean getHasPrePage() {
		if (currentPage <= 1) {
			return false;
		}
		return true;
	}
	public int getPrePage(){
		if(getHasPrePage()){
		return this.currentPage-1;}
		else{
			return this.currentPage;
		}
	}
	public int getNextPage(){
		if(getHasNextPage()){
		return this.currentPage+1;
		}
		else{
			return this.currentPage;
		}
	}
	
	public List findPagination(List list){
		List lst = new ArrayList();
		int index=0;
		if(currentPage>0){
			index=(currentPage-1)*pageSize;
		}
		for (int i = index; i < index+pageSize && i<list.size(); i++) {
			lst.add(list.get(i));
		}
		return lst;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public void setTotalLines(int totalLines) {
		this.totalLines = totalLines;
	}
}
